namespace = cr_hajj_punishment

# Rebuilds the Caliphal Chastisement if the offender remains in crisis
# and the previous punishment war ended without reconciliation.
long_character_event = {
	id = cr_hajj_punishment.2
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_character_flag = cr_hajj_crisis
		NOT = {
			any_war = { using_cb = cr_caliphal_chastisement }
		}
	}

	immediate = { cr_hajj_create_chastisement_effect = yes }
}

# The offender is informed that the rightful Caliph has issued chastisement.
long_character_event = {
	id = cr_hajj_punishment.20
	title = CR_HAJJ_PUNISHMENT_20_TITLE
	desc = CR_HAJJ_PUNISHMENT_20_DESC
	picture = GFX_cr_evt_religious_exultation
	border = GFX_event_long_frame_religion
	is_triggered_only = yes
	option = { name = CR_HAJJ_PUNISHMENT_20_A }
}

# Player-controlled co-religionists are visibly summoned.
# Only landed counts and above can receive the call.
long_character_event = {
	id = cr_hajj_punishment.21
	title = CR_HAJJ_PUNISHMENT_21_TITLE
	desc = CR_HAJJ_PUNISHMENT_21_DESC
	picture = GFX_cr_evt_council
	border = GFX_event_long_frame_religion
	is_triggered_only = yes

	trigger = {
		ai = no
		is_landed = yes
		higher_tier_than = BARON
		religion = event_target:cr_hajj_punishment_caliph
		event_target:cr_hajj_offender = {
			is_alive = yes
			has_character_flag = cr_hajj_crisis
		}
		event_target:cr_hajj_war_legate = {
			is_alive = yes
			has_character_flag = cr_caliphal_hajj_legate
		}
	}

	option = {
		name = CR_HAJJ_PUNISHMENT_21_A
		join_defender_wars = event_target:cr_hajj_war_legate
	}
}

# The rightful Caliph selects a path of repentance.
long_character_event = {
	id = cr_hajj_punishment.30
	title = CR_HAJJ_PUNISHMENT_30_TITLE
	desc = CR_HAJJ_PUNISHMENT_30_DESC
	picture = GFX_cr_evt_council_speaker
	border = GFX_event_long_frame_religion
	is_triggered_only = yes

	trigger = {
		event_target:cr_hajj_penitent = {
			is_alive = yes
			has_character_flag = cr_hajj_crisis
		}
	}

	option = {
		name = CR_HAJJ_PUNISHMENT_30_A
		ai_chance = { factor = 35 modifier = { factor = 1.5 trait = greedy } }
		event_target:cr_hajj_penitent = { long_character_event = { id = cr_hajj_punishment.31 } }
	}
	option = {
		name = CR_HAJJ_PUNISHMENT_30_B
		ai_chance = { factor = 35 modifier = { factor = 1.5 trait = proud } }
		event_target:cr_hajj_penitent = { long_character_event = { id = cr_hajj_punishment.32 } }
	}
	option = {
		name = CR_HAJJ_PUNISHMENT_30_C
		ai_chance = { factor = 30 modifier = { factor = 1.5 trait = zealous } }
		event_target:cr_hajj_penitent = { long_character_event = { id = cr_hajj_punishment.33 } }
	}
}

long_character_event = {
	id = cr_hajj_punishment.31
	title = CR_HAJJ_PUNISHMENT_31_TITLE
	desc = CR_HAJJ_PUNISHMENT_31_DESC
	picture = GFX_cr_evt_council_speaker
	border = GFX_event_long_frame_religion
	is_triggered_only = yes

	option = {
		name = CR_HAJJ_PUNISHMENT_31_A
		cr_hajj_penance_tithe_effect = yes
	}
	option = {
		name = CR_HAJJ_PUNISHMENT_REFUSE
		clr_character_flag = cr_hajj_penance_pending
		piety = -100
		prestige = -100
		decadence = 2
	}
}

long_character_event = {
	id = cr_hajj_punishment.32
	title = CR_HAJJ_PUNISHMENT_32_TITLE
	desc = CR_HAJJ_PUNISHMENT_32_DESC
	picture = GFX_cr_evt_council_speaker
	border = GFX_event_long_frame_religion
	is_triggered_only = yes

	option = {
		name = CR_HAJJ_PUNISHMENT_32_A
		cr_hajj_penance_abasement_effect = yes
	}
	option = {
		name = CR_HAJJ_PUNISHMENT_REFUSE
		clr_character_flag = cr_hajj_penance_pending
		piety = -100
		prestige = -100
		decadence = 2
	}
}

long_character_event = {
	id = cr_hajj_punishment.33
	title = CR_HAJJ_PUNISHMENT_33_TITLE
	desc = CR_HAJJ_PUNISHMENT_33_DESC
	picture = GFX_cr_evt_council_speaker
	border = GFX_event_long_frame_religion
	is_triggered_only = yes

	option = {
		name = CR_HAJJ_PUNISHMENT_33_A
		cr_hajj_penance_submission_effect = yes
	}
	option = {
		name = CR_HAJJ_PUNISHMENT_REFUSE
		clr_character_flag = cr_hajj_penance_pending
		piety = -100
		prestige = -100
		decadence = 2
	}
}

# Hajj failure is personal. Death ends the crisis and does not pass it to an heir.
long_character_event = {
	id = cr_hajj_punishment.90
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		OR = {
			has_character_flag = cr_hajj_active
			has_character_flag = cr_hajj_crisis
		}
	}

	immediate = {
		if = {
			limit = { has_character_flag = cr_hajj_crisis }
			cr_hajj_end_caliphal_wars_effect = yes
			cr_hajj_clear_crisis_state_effect = yes
		}
		cr_hajj_clear_journey_effect = yes
	}
}
